// C includes
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

// prototype for thread routine
void* print(void*);

// structure to hold data passed to a thread
typedef struct thdata_ {
    int number;
    char message[100];
} thdata;

int main() {
    pthread_t thread1, thread2;
    thdata data1, data2;
    
    // initialize data to pass to thread 1
    data1.number = 1;
    strcpy(data1.message, "Hello!");

    // initialize data to pass to thread 2
    data2.number = 2;
    strcpy(data2.message, "Goodbye!");
    
    // create threads
    pthread_create (&thread1, NULL, &print, (void *) &data1);
    pthread_create (&thread2, NULL, &print, (void *) &data2);

    // wait for threads to terminate.
    pthread_join(thread1, NULL);
    pthread_join(thread2, NULL);
}

void* print(void *ptr) {
    thdata *data;
    data = (thdata *) ptr;
    
    printf("Thread %d says %s \n", data->number, data->message);
    
    pthread_exit(0);
}
